<?php include("includes/session.php"); ?>
<?php include("includes/connect_db.php"); ?>
<?php include("includes/header.php"); ?>
<?php include("notif.php"); ?>

<style>
	div{
		font-family: 'SEGOE UI';
	}

	input{
		width: 400px;
	}
	.btn{
		width: 100px;
	}
</style>

<div class="span9">  
    <h3>SMS</h3>                      
    <ul class="breadcrumb well">
    	<li><a href="kontak.php">Koneksi</a> <span class="divider">/</span></li>
        <li class="active">Tambah</li>                
    </ul>    
    <div class="alert alert-info">
		Tambah Koneksi
    </div>
    
	<form class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    	<div>
			<div class="control-group">
				<label class="control-label">Nama Host</label>
				<div class="controls">
					<input placeholder="Masukkan Nama Host" type="text" name="nama_host" value="<?php echo $_POST['nama_host']; ?>">
				</div>
			</div>
			
			<div class="control-group">
				<label class="control-label">Alamat IP</label>
				<div class="controls">
					<input placeholder="Masukkan Alamat IP Host" type="text" name="host" value="<?php echo $_POST['host']; ?>">
				</div>
			</div>
			
			<div class="control-group">
				<label class="control-label">Username Host</label>
				<div class="controls">
					<input placeholder="Masukkan Username Host" type="text" name="username" value="<?php echo $_POST['username']; ?>">
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">Password</label>
				<div class="controls">
					<input placeholder="Masukkan Password Host" type="password" name="pass" value="<?php echo $_POST['pass']; ?>">
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">Database</label>
				<div class="controls">
					<input placeholder="Masukkan Database Yang Digunakan" type="text" name="database" value="<?php echo $_POST['database']; ?>">
				</div>
			</div>
		</div>
		<div>
			<div class="span12">
				<ul class="breadcrumb well">
					<button type="submit" class="btn btn-info" name="simpan">
						<i class="icon-white icon-download-alt"></i>
						Simpan
					</button>
					<button type="submit" class="btn btn-danger" name="batal">
						<i class="icon-white icon-remove"></i>
						Batal
					</button>
				</ul>
			</div>
		</div>
	</form>
</div>

<?php
	if(isset($_POST['simpan'])){
		$nama_host = $_POST['nama_host'];
		$host = $_POST['host'];
		$username = $_POST['username'];
		$pass = $_POST['pass'];
		$database = $_POST['database'];

		if (empty($nama_host) or empty($host) or empty($username) or empty($database)){
            echo "<SCRIPT> alert('Isi Data Terlebih dahulu');</SCRIPT>";
        } else{
    		$sql_input_koneksi = "INSERT INTO tb_host (nama_host, host, username, password, db) 
    								VALUES ('$nama_host', '$host', '$username', '$pass', '$database') ";

			$query_input_koneksi = mysql_query($sql_input_koneksi) or die(mysql_error());

			if ($query_input_koneksi) {
				echo "<SCRIPT> alert('Data Disimpan'); location.href='host.php';</SCRIPT>";
			} else {
				echo "<SCRIPT> alert('Data Gagal Disimpan');</SCRIPT>";
			}
	  	}
	} elseif (isset($_POST['batal'])) {
		echo "<SCRIPT> location.href='host.php';</SCRIPT>";
	}
?>

<?php include("includes/footer.php"); ?>

<script type="text/javascript">
	
</script>